Date.js ➔ GDate   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 14
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
c 1
b 0
f 0
nc 3
nop 1
dl 14
loc 14
rs 9.4285
1 View Code Duplication
var GedcomX = require('../'),
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2
    utils = require('../utils');
3
4
/**
5
 * A date.
6
 * 
7
 * @see {@link https://github.com/FamilySearch/gedcomx/blob/master/specifications/json-format-specification.md#conclusion-date|GEDCOM X JSON Spec}
8
 * 
9
 * @class
10
 * @extends ExtensibleData
11
 * @param {Object} [json]
12
 * @alias Date
13
 */
14
var GDate = function(json){
15
  
16
  // Protect against forgetting the new keyword when calling the constructor
17
  if(!(this instanceof GDate)){
18
    return new GDate(json);
19
  }
20
  
21
  // If the given object is already an instance then just return it. DON'T copy it.
22
  if(GDate.isInstance(json)){
23
    return json;
24
  }
25
  
26
  this.init(json);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
27
};
28
29
GDate.prototype = Object.create(GedcomX.ExtensibleData.prototype);
30
31
GDate._gedxClass = GDate.prototype._gedxClass = 'GedcomX.Date';
32
33
GDate.jsonProps = [
34
  'original',
35
  'formal'
36
];
37
38
/**
39
 * Check whether the given object is an instance of this class.
40
 * 
41
 * @param {Object} obj
42
 * @returns {Boolean}
43
 */
44
GDate.isInstance = function(obj){
45
  return utils.isInstance(obj, this._gedxClass);
46
};
47
48
/**
49
 * Initialize from JSON
50
 * 
51
 * @param {Object}
0 ignored issues
show
Documentation introduced by
The parameter * does not exist. Did you maybe forget to remove this comment?
Loading history...
52
 * @return {Date} this
53
 */
54
GDate.prototype.init = function(json){
55
  
56
  GedcomX.ExtensibleData.prototype.init.call(this, json);
57
  
58
  if(json){
59
    this.setOriginal(json.original);
60
    this.setFormal(json.formal);
61
  }
62
  return this;
63
};
64
65
/**
66
 * Get the original date value
67
 * 
68
 * @returns {String} original
69
 */
70
GDate.prototype.getOriginal = function(){
71
  return this.original;
72
};
73
74
/**
75
 * Set the original date value
76
 * 
77
 * @param {String} original
78
 * @returns {Date} This instance.
79
 */
80
GDate.prototype.setOriginal = function(original){
81
  this.original = original;
82
  return this;
83
};
84
85
/**
86
 * Get the formal date value
87
 * 
88
 * @returns {String}
89
 */
90
GDate.prototype.getFormal = function(){
91
  return this.formal;
92
};
93
94
/**
95
 * Set the formal date value
96
 * 
97
 * @param {String} formal
98
 * @returns {Date} This instance.
99
 */
100
GDate.prototype.setFormal = function(formal){
101
  this.formal = formal;
102
  return this;
103
};
104
105
/**
106
 * Export the object as JSON
107
 * 
108
 * @return {Object} JSON object
109
 */
110
GDate.prototype.toJSON = function(){
111
  return this._toJSON(GedcomX.ExtensibleData, GDate.jsonProps);
112
};
113
114
module.exports = GDate;